package top.infopub.mgr.cap.web;

import com.github.pagehelper.Page;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import top.infopub.mgr.cap.service.FinancingMakeLoansService;
import top.infopub.mgr.cap.service.FundingApprovalService;
import top.infopub.mgr.common.page.ParamPage;
import top.infopub.mgr.common.vo.RspVo;
import top.infopub.model.cap.FinancingMakeLoans;
import top.infopub.model.cap.FundingApproval;

import java.text.ParseException;
import java.text.SimpleDateFormat;

/**
 * @Author Warking
 * @Date 2021/5/24 13:49
 * @Version 1.0 融资还款
 */
@Controller
@RequestMapping("/financingMakeLoans")
public class FinancingMakeLoansController {

    @Autowired
    private FinancingMakeLoansService financingMakeLoansService;

    /*融资还款列表接口*/
    @RequestMapping("/queryDataByCondition")
    @ResponseBody
    public RspVo<FinancingMakeLoans> queryDataByCondition(FinancingMakeLoans financingMakeLoans, ParamPage paramPage) throws ParseException {
        Page<FinancingMakeLoans> page = new Page();
        page.setPageNum(paramPage.getPage());
        page.setPageSize(paramPage.getLimit());
        //处理时间范围
        if (!StringUtils.isEmpty(financingMakeLoans.getDates()))
        {
            String[] splitTime = financingMakeLoans.getDates().split("~");
            SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd");
            financingMakeLoans.setStartDate(format.parse(splitTime[0]));
            financingMakeLoans.setEndDate(format.parse(splitTime[1]));
        }
        page = financingMakeLoansService.selectPage(page,financingMakeLoans );
        return RspVo.getSuccessResponse(page.getTotal(),page.getResult());
    }


}
